import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';

import { UserModule } from '@src/user/user.module';
import { RedisModule } from '@src/redis/redis.module';
import { ConfigurationModule } from '@src/config/configuration.module';
import { ConfigurationService } from '@src/config/configuration.service';

import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { LocalStrategy } from './strategy/local.strategy';
import { JwtStrategy } from './strategy/jwt.strategy';

@Module({
  imports: [
    ConfigurationModule,
    UserModule,
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigurationModule],
      useFactory: (configurationService: ConfigurationService) => ({
        secret: configurationService.app.jwtSecret,
        signOptions: {
          expiresIn: configurationService.app.jwtExpiresIn,
        },
      }),
      inject: [ConfigurationService],
    }),
    RedisModule,
  ],
  controllers: [AuthController],
  providers: [AuthService, LocalStrategy, JwtStrategy],
})
export class AuthModule {}
